﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace TomNet.App.Web.Common
{
	public class Utility
	{
		#region string ConvertHashrate(decimal hr, string unit = "", string space = "") 算力数值转换。

		/// <summary>
		/// 算力数值转换。
		/// </summary>
		/// <param name="hr">算力数值</param>
		/// <param name="unit">转换单位（byte、K、M、G、T，为空时获取最大单位）</param>
		/// <param name="space">算力数值与单位的间隔字符</param>
		/// <returns></returns>
		public static string ConvertHashrate(decimal hr, string unit = "", string space = "")
		{
			string result = string.Empty;

			result = hr.ToString("0.00") + space + "byte";
			if (unit.Equals("byte", StringComparison.CurrentCultureIgnoreCase)) goto Finally;

			if (hr > 1000)
			{
				hr = hr / 1000;
				result = hr.ToString("0.00") + space + "K";
				if (unit.Equals("K", StringComparison.CurrentCultureIgnoreCase)) goto Finally;
			}

			if (hr > 1000)
			{
				hr = hr / 1000;
				result = hr.ToString("0.00") + space + "M";
				if (unit.Equals("M", StringComparison.CurrentCultureIgnoreCase)) goto Finally;
			}

			if (hr > 1000)
			{
				hr = hr / 1000;
				result = hr.ToString("0.00") + space + "G";
				if (unit.Equals("G", StringComparison.CurrentCultureIgnoreCase)) goto Finally;
			}

			if (hr > 1000)
			{
				hr = hr / 1000;
				result = hr.ToString("0.00") + space + "T";
				if (unit.Equals("T", StringComparison.CurrentCultureIgnoreCase)) goto Finally;
			}

			Finally:
			return result;
		}

		#endregion

		#region string BusinessStateString(int s) 订单状态的中文表示。

		/// <summary>
		/// 订单状态的中文表示。
		/// </summary>
		/// <param name="s"></param>
		/// <returns></returns>
		public static string BusinessStateString(int s)
		{
			string result = string.Empty;

			switch (s)
			{
				case 1: result = "开机"; break;
				case 2: result = "关机"; break;
				case 3: result = "停机";break;
			}

			return result;
		}

		#endregion
	}
}
